﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using NetCoreConfigIntroduce.Models;
using NetCoreConfigIntroduce.Options;

namespace NetCoreConfigIntroduce.Controllers
{
    public class HomeController : Controller
    {
        private readonly IOptions<AutoConfig> _autoConfigOptions;
        private readonly IOptions<Profile> _profileOptions;
        private readonly IOptions<Collection<Profile>> _profilesOptions;
        private readonly IOptions<Dictionary<string, Profile>> _dictionaryOptions;

        public HomeController(
            IOptions<AutoConfig> autoConfigOptions,
            IOptions<Profile> profileOptions,
            IOptions<Collection<Profile>> profilesOptions,
            IOptions<Dictionary<string, Profile>> dictionaryOptions)
        {
            this._autoConfigOptions = autoConfigOptions;
            this._profileOptions = profileOptions;
            this._profilesOptions = profilesOptions;
            _dictionaryOptions = dictionaryOptions;

            //autoconfig
            var name = autoConfigOptions.Value.Name;
            var ExpiredTime = autoConfigOptions.Value.ExpiredTime;

            //profile
            var gender = _profileOptions.Value.Gender;
            var age = _profileOptions.Value.Age;
            var ContactInfo = _profileOptions.Value.ContactInfo;

            //read profiles
            var count = profilesOptions.Value.Count;
            var gender0 = profilesOptions.Value[0].Gender;

            //read dictionary profiles
            var count2 = _dictionaryOptions.Value.Count;
            var foo = _dictionaryOptions.Value["foo"];
        }

        public IActionResult Index()
        {
            var name = _autoConfigOptions.Value.Name;
            var ExpiredTime = _autoConfigOptions.Value.ExpiredTime;
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
